<?php

namespace app\helps;
use app\facade\Redis;
use think\Db;

/**
 * 奖金(团队/直推)操作记录表
 * Class MoneyBonusHelper
 * @package app\helps
 */
class MoneyBonusHelper extends MoneyHelperBaser{

    /**
     * 换购商品 消耗奖金（团队/直推）
     * @param $user 发放用户
     * @param $num  数量
     * @param $goods 商品
     */
    public function exchangeGoodsByInComeProfit($user,$num,$goods){
        $type = self::TYPE_BONUS;
        $op_type =self::OP_TYPE_INCOME_TO_GOODS;
        $msg="用户用奖金购买商品:".$goods["name"];
        $res = $this->reduceUserMoneyAndRecord($user,$num,self::FILED_INCOME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        return 1;
    }

    /**
     * 换购兑换券 消耗奖金（团队/直推）
     * @param $user 发放用户
     * @param $num  数量
     * @param $msg 备注
     */
    public function exchangeVolumeByInComeProfit($user,$income,$volume){
        $type = self::TYPE_BONUS;
        $op_type =self::OP_TYPE_INCOME_TO_VOLUME;
        $msg="用户用奖金".$income."兑换".$volume."兑换券";
        $res = $this->reduceUserMoneyAndRecord($user,$income,self::FILED_INCOME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        $type = self::TYPE_VOLUME;
        $op_type =self::OP_TYPE_VOLUME_FROM_INCOME;
        $msg="用户用奖金".$income."兑换".$volume."兑换券";
        $res = $this->addUserMoneyAndRecord($user,$volume,self::FILED_VOLUME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        return 1;
    }

    /**
     * 发放团队收益
     * @param $user 发放收益用户
     * @param $num  数量
     * @param $msg 备注
     */
    public function teamProfit($user,$num,$msg){
        $type = self::TYPE_BONUS;
        $op_type =self::OP_TYPE_INCOME_TEAM;
        $res = $this->addUserMoneyAndRecord($user,$num,self::FILED_INCOME,$msg,$type,$op_type,self::PROFIT_TYPE_TEAM);
        if ($res!=1){
            return $res;
        }
        return 1;
    }

    /**
     * 发放直推收益的
     * @param $user 发放收益用户
     * @param $num  数量
     * @param $msg 备注
     */
    public function childProfit($user,$num,$msg){
        $type = self::TYPE_BONUS;
        $op_type =self::OP_TYPE_INCOME_CHILD;
        $res = $this->addUserMoneyAndRecord($user,$num,self::FILED_INCOME,$msg,$type,$op_type,self::PROFIT_TYPE_CHILD);
        if ($res!=1){
            return $res;
        }
        return 1;
    }




}